package com.springboot.bigevent.controller;

import com.springboot.bigevent.pojo.Article;
import com.springboot.bigevent.pojo.PageBean;
import com.springboot.bigevent.pojo.Result;
import com.springboot.bigevent.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping
    public Result add(@RequestBody @Validated Article article){
        articleService.add(article);
        return Result.success();
    }
    @GetMapping
    public Result<PageBean<Article>> list(Integer pageNum,
                                          Integer pageSize,
                                          @RequestBody(required = false) String categoryId,
                                          @RequestBody(required = false) String state){
        //required = false 表示这个参数可以为空

        PageBean<Article> pb = articleService.list(pageNum,pageSize,categoryId,state);
        return Result.success(pb);
    }

    @DeleteMapping
    public Result delete(@RequestBody String id){
        articleService.delete(id);
        return Result.success();
    }

    }

